package Thread;

import java.util.Scanner;

public class ThreadDemo9 {
     static class Cpounter{
        volatile public int flag=0;
    }
    public static void main(String[] args) {
        Cpounter cpounter=new Cpounter();
        Thread t1=new Thread(){
            @Override
            public void run() {
                while (cpounter.flag==0){

                }
            }
        };
        t1.start();
        Thread t2=new Thread(){
            @Override
            public void run() {
                System.out.println("请输入:");
                Scanner scanner=new Scanner(System.in);
                cpounter.flag=scanner.nextInt();
            }
        };

        t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("线程结束");
    }
}
